/**
 * 
 */
package neptune.web.client.view;

import neptune.web.client.controller.ExperimentSummaryViewController;
import neptune.web.client.services.ApplicationDataProvider;
import neptune.web.client.view.components.ExperimentTableRenderer;

import org.gwtlib.client.table.ColumnLayout;
import org.gwtlib.client.table.ui.Column;
import org.gwtlib.client.table.ui.PagingBar;
import org.gwtlib.client.table.ui.PagingTable;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * @author Roberto Bifulco [info@robertobifulco.it, robertobifulco.it]
 *
 */
public class ExperimentSummaryView extends View {

	public static final String DEFAULT_TOKEN = "ExperimentSummary";
	private PagingTable table;

	public ExperimentSummaryView() {

		// Setting view params
		try {
			this.setName(DEFAULT_TOKEN);
		} catch (DuplicatedTokenException e) {
			ConsoleManager.addConsoleDebugMessage(e.getMessage(), true);
		}

		Column[] colums = { new Column(0, true, "Experiment", "30%", new ExperimentTableRenderer()),
				new Column(1, true, "Administrator", "30%"),
				new Column(2, true, "State", "20%"),
				new Column(3, true, "Creation Date","20%")};

		ColumnLayout layout = new ColumnLayout(colums);
		
		int expNumber = ApplicationDataProvider.getInstance().getExperimentsNumber();
		
		table = new PagingTable(layout, new PagingBar(expNumber, 10));
		table.setContentProvider(new ExperimentSummaryViewController(table));
		table.setSize(10);
		
		table.setWidth("90%");
		
		VerticalPanel panel = new VerticalPanel();
		panel.add(table);
		Frame frame = new Frame(GWT.getModuleBaseURL() + "ExperimentsSummary.html");
		panel.add(frame);
		frame.setHeight("300px");
		frame.setWidth("90%");
		panel.setCellWidth(frame, "100%");

		frame.setStylePrimaryName("ExperimentSummaryView-frame");
		panel.setStyleName("ExperimentSummaryView");

		initWidget(panel);
	}

	public void update(){
//		Ridisegna la tabella
		table.getPagingBar().setSize(ApplicationDataProvider.getInstance().getExperimentsNumber());
		table.getPagingBar().update();
//		table.update();
	}
	
	public void reset(){
//		Azzera la cache della tabella
		table.reset();
	}
}
